package com.ruirenyun.util.annotation.validator;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;

/**
 * Created with IntelliJ IDEA.
 *
 * @author Deng Ye
 * @version 1.0
 * @date 2020/9/14
 * @description
 * @modifiedBy
 */
public class NonNegativeValidator implements ConstraintValidator<NonNegative, Object> {
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(BigDecimal.ZERO) > 0;
        }
        if (value instanceof Integer) {
            return ((Integer) value) > 0;
        }
        if (value instanceof Long) {
            return ((Long) value > 0);
        }
        if (value instanceof Double) {
            return (Double) value > 0;
        }
        if(value instanceof Float) {
            return (Float) value > 0;
        }

        return false;
    }
}
